package dapps.web.proj;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.CRUDActionSupport;

import dapps.entity.proj.Plan;
import dapps.service.proj.PlanManager;


@SuppressWarnings("serial")
@Results( { 
	@Result(name = CRUDActionSupport.RELOAD, location = "projplan!input.action?page.pageRequest=${page.pageRequest}", type = "redirect"),
	})
public class ProjplanAction extends CRUDActionSupport<Plan> {

	@Autowired
	private PlanManager planManager;


	// 基本属性
	private Plan entity;
	private Long id;
	private String[] plannames ={"--","项目申报启动","项目申报结束","项目补报启动","项目补报结束","项目计划下达","进度申报启动","进度申报结束"};
	
	private Page<Plan> page = new Page<Plan>(6);
	
	// 角色相关属性

	// 基本属性访问函数 //


	public Plan getModel() {
		return entity;
	}
	public Page<Plan> getPage() {
		return page;
	}
	public void setId(Long id) {
		this.id = id;
	}
	@Override
	protected void prepareModel() throws Exception {		

	}

	// CRUD Action 函数 //


	
	@Override
	public String list() throws Exception {
		
		page.setOrder("desc");page.setOrderBy("yeartime");
		page = planManager.getAll(page);
		return SUCCESS;
	}

	
	@Override
	public String input() throws Exception {
		page.setOrder("desc");page.setOrderBy("yeartime");
		page = planManager.getAll(page);
		return INPUT;
	}

	@Override
	public String save() throws Exception {
		if (id != null) {
			entity = planManager.get(id);
		} else {
			return RELOAD;
		}

		if (entity.getStatus() != 5)
			entity.setStatus(5);
		else
			entity.setStatus(4);
		planManager.save(entity);
		addActionMessage("保存状态成功");

		return RELOAD;
	}

	
	@Override
	public String delete() throws Exception {
		return RELOAD;
	}
	public String[] getPlannames() {
		return plannames;
	}

	// 其他属性访问函数与Action函数 //




}
